home *** CD-ROM | disk | FTP | other *** search
- /* ======================
- * PedPaneIconAnimated.cc
- * ======================
- */
-
- #include "PedestalDebugging.h"
-
- #include <Icons.h>
-
- #include "PedPaneIconAnimated.hh"
-
- #include "PedView.hh"
- #include "Ped1AppProcess.hh"
- #include "PedApplication.hh"
-
- static
- void
- AnimateIcon(void *inParam)
- {
- if (inParam == NULL) return;
-
- PedPaneIconAnimated *icon = (PedPaneIconAnimated *)inParam;
- icon->Animate();
- }
-
- PedPaneIconAnimated::PedPaneIconAnimated(PedView &inSuperView)
- : PedPaneIcon(inSuperView), mAnimating(false)
- , mCountFrames(0), mCurrentFrame(0), mTicksPerFrame(4), mLastAdvance(0)
- , mAnimateChore(NULL)
- {
- mCountFrames = 32;
- mAnimateChore = new PedChoreGeneric(&AnimateIcon, (void *)this);
- }
-
- PedPaneIconAnimated::~PedPaneIconAnimated()
- {
- Ped1AppProcess::Me().MainModule().UnscheduleRepeatChore(mAnimateChore);
- delete mAnimateChore;
- }
-
- void
- PedPaneIconAnimated::Draw()
- {
- Rect rect;
- //::SetRect(&rect, 0, 0, 128, 128);
- rect = mBounds;
- Point offset;
- mSuperView.GetWindowToLocalOffset(offset);
- ::OffsetRect(&rect, offset.h, offset.v);
- if (mCountFrames > 0) {
- long range = 64;
- long eccentricity = 2 * (mCurrentFrame - (mCountFrames / 2)) * (range / mCountFrames);
- if (eccentricity < 0) {
- eccentricity = -eccentricity;
- }
- ::InsetRect(&rect, eccentricity, range - eccentricity);
- }
- //::EraseRect(&rect);
- //::PlotIconID(&mBounds, atAbsoluteCenter, ttNone, 128);
- ::PlotIconID(&rect, atAbsoluteCenter, ttNone, 128);
- }
-
- void
- PedPaneIconAnimated::Animate()
- {
- mSuperView.Focus();
- if (mAnimating) {
- long ticks = ::TickCount();
- if (ticks - mLastAdvance > mTicksPerFrame && mCountFrames > 0) {
- mCurrentFrame = (mCurrentFrame + 1) % mCountFrames;
- mLastAdvance = ticks;
- ::EraseRect(&mBounds);
- Draw();
- }
- //Ped1AppProcess::Me().MainModule().ScheduleRepeatChore(mAnimateChore);
- }
- }
-
- void
- PedPaneIconAnimated::DispatchClickEvent(EventRecord &inEvent)
- {
- if (mAnimating = !mAnimating) {
- Ped1AppProcess::Me().MainModule().ScheduleRepeatChore(mAnimateChore);
- } else {
- Ped1AppProcess::Me().MainModule().UnscheduleRepeatChore(mAnimateChore);
- }
-
- //::SetPort(macWindow);
- ::GlobalToLocal(&inEvent.where);
- }
-
- void
- PedPaneIconAnimated::DispatchNullEvent(EventRecord &inEvent)
- {
- mSuperView.Focus();
- ::GlobalToLocal(&inEvent.where);
- if (::PtInRect(inEvent.where, &mBounds)) {
- CursHandle cursCross = ::GetCursor(crossCursor);
- ThrowIfNULL_(cursCross);
- ::SetCursor(*cursCross);
- } else
- ::SetCursor(&qd.arrow);
- }
-